package com.putao.album.tinyalbum;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.google.gson.Gson;
import com.loopj.android.http.RequestParams;
import com.putao.album.R;
import com.putao.album.album.ActivityAlbumPhotoSelect;
import com.putao.album.base.BaseActivity;
import com.putao.album.dialog.ConfirmDialogBuilder;
import com.putao.album.dialog.WriteStoryDialog;
import com.putao.album.eventbus.BasePostEvent;
import com.putao.album.fileupload.FileInfo;
import com.putao.album.fileupload.FileUploadDBHelper;
import com.putao.album.photodetail.ActivityPhotoDetail;
import com.putao.album.popupwindow.PtThirdSharePopupWindow;
import com.putao.album.tinyalbum.adapter.TinyAblumAdapter;
import com.putao.album.tinyalbum.bean.TinyAlbumItem;
import com.putao.album.tinyalbum.view.ExpandableTextView;
import com.putao.album.util.ActivityHelper;
import com.putao.album.util.CommonUtils;
import com.putao.album.util.HttpRequestUtil;
import com.putao.album.util.Loger;
import com.putao.album.util.PuTaoConstants;
import com.putao.album.util.StringHelper;
import com.putao.album.util.UmengTouchEvent;
import com.putao.album.widget.pullrefresh.PullToRefreshBase;
import com.putao.album.widget.pullrefresh.PullToRefreshGridView;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.greenrobot.event.EventBus;

/**
 * Created by chen on 15/4/28.
 * <p/>
 * 时光轴相册页面
 */
public class ActivityTinyAlbum extends BaseActivity {
    private TextView title_tv;
    private Button back_btn, right_btn;
    private PullToRefreshGridView gv_album;
    private TinyAblumAdapter mTinyAblumAdapter;
    private List<TinyAlbumItem.AlbumItem> mDatalist = new ArrayList<TinyAlbumItem.AlbumItem>();
    private int nextPage = 1;
    private boolean mIsLastPage = false;
    private boolean mIsRefreshing = false;
    private String album_id = "1";

    private LinearLayout story_view;
    //    private LinearLayout tag_view_ll;
//    private PtTagListView tag_view;
    private ExpandableTextView story_tv;
    private ImageView tips_kiss;
    private TextView kiss_num;
    private ImageView share;
    //    private TextView owner;
//    private final List<PtTag> mTags = new ArrayList<PtTag>();
    private TinyAlbumItem mTinyAlbumItem;
    //    private ImageView add_tag;
    private boolean deleteMode;
    private static String ADD_TAG_BTN = "添加...";
    private LinearLayout operate_btn;
    private Button btn_delete;
    private ImageView no_photos;
    private PopupWindow mPopupWindow;
    private TextView story_tv_operate;
//    private ImageView story_write_icon;

    @Override
    public int doGetContentViewId() {
        return R.layout.activity_tiny_album;
    }

    @Override
    public void doInitSubViews(View view) {
        back_btn = queryViewById(R.id.back_btn);
        title_tv = queryViewById(R.id.title_tv);
        right_btn = queryViewById(R.id.right_btn, true);
        right_btn.setVisibility(View.INVISIBLE);

        story_view = (LinearLayout) queryViewById(R.id.story_view);
        story_tv = (ExpandableTextView) queryViewById(R.id.story_tv);
        story_tv_operate = (TextView) queryViewById(R.id.story_tv_operate);
//        tag_view_ll = (LinearLayout) queryViewById(R.id.tag_view_ll);
//        tag_view = (PtTagListView) queryViewById(R.id.tag_view);
//        tag_view.setTagViewBackgroundRes(R.drawable.tag_black_half_transparent);

//        add_tag = (ImageView) queryViewById(R.id.add_tag);
        tips_kiss = (ImageView) queryViewById(R.id.tips_kiss);
        kiss_num = (TextView) queryViewById(R.id.kiss_num);
        share = (ImageView) queryViewById(R.id.share);
//        owner = (TextView) queryViewById(R.id.owner);

        operate_btn = (LinearLayout) queryViewById(R.id.operate_btn);
        btn_delete = (Button) queryViewById(R.id.btn_delete);
        no_photos = (ImageView) queryViewById(R.id.no_photos);

//        story_write_icon = (ImageView) queryViewById(R.id.story_write_icon);

        addOnClickListener(R.id.back_btn, R.id.kiss_layout, R.id.share_layout, R.id.btn_delete, R.id.no_photos, R.id.story_view, R.id.go_delete, R.id.story_tv_operate);

        gv_album = queryViewById(R.id.gv_album);
        gv_album.setOnItemClickListener(onItemClickListener);
        gv_album.getRefreshableView().setOnItemClickListener(onItemClickListener);
        gv_album.getRefreshableView().setNumColumns(2);
        gv_album.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<GridView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {
                refreshData();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {

            }
        });
        gv_album.setOnLastItemVisibleListener(new PullToRefreshBase.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {
                doGetData();
            }
        });

//        tag_view.setOnTagClickListener(new PtTagListView.OnTagClickListener() {
//            @Override
//            public void onTagClick(PtTagView tagView, PtTag tag) {
//
//                if (ADD_TAG_BTN.equals(tag.getTitle())) {
//                    showTagManagerDialog();
//                }
//            }
//        });
    }

    void refreshData() {
        nextPage = 1;
        mIsLastPage = false;
        doGetData();
    }

    AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (isDeleteMode()) {

                TinyAlbumItem.AlbumItem item = mDatalist.get(position);

                if (item.isChoose()) {
                    item.setChoose(false);
                } else {
                    item.setChoose(true);
                }
                updateDeleteBtnText();
                mTinyAblumAdapter.notifyDataSetChanged();

            } else {
                ArrayList<String> ids = new ArrayList<String>();
                for (int i = 0; i < mDatalist.size(); i++) {
                    ids.add(mDatalist.get(i).getPhoto_id());
                }
                Bundle bundle = new Bundle();
                bundle.putStringArrayList("ids", ids);
                bundle.putInt("position", position);
                ActivityHelper.startActivity(mActivity, ActivityPhotoDetail.class, bundle);
            }

        }
    };


    private void updateDeleteBtnText() {

        int chooseNum = getChoosePhotosNum();
        String btnText = getString(R.string.btn_delete);
        if (chooseNum > 0) {
            btnText = btnText + " " + chooseNum;
        }
        btn_delete.setText(btnText);
    }

    /**
     * 获取已经选择的照片数目
     *
     * @return
     */
    private int getChoosePhotosNum() {
        int chooseNum = 0;
        for (int i = 0; i < mDatalist.size(); i++) {
            if (mDatalist.get(i).isChoose()) {
                chooseNum++;
            }
        }
        return chooseNum;
    }

    @Override
    public void doInitData() {
        try {
            Bundle bundle = getIntent().getExtras();
            album_id = bundle.getString("albumId");
        } catch (Exception e) {
            e.printStackTrace();
        }

        mTinyAblumAdapter = new TinyAblumAdapter(mContext, mDatalist);
        gv_album.setAdapter(mTinyAblumAdapter);
        mTinyAblumAdapter.notifyDataSetChanged();
        doGetData();
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Bundle bundle = new Bundle();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onBackPressed() {
        if (isDeleteMode()) {
            setDeleteMode(false);
        } else {
            super.onBackPressed();
        }
    }

    public void onEvent(BasePostEvent event) {
        switch (event.eventCode) {
            case PuTaoConstants.EVENTBUS_PHOTO_DELETED:
                Bundle bundle = event.bundle;
                boolean deleteAll = bundle.getBoolean("deleteAll", false);
                if (deleteAll) {
                    showToast("已经全部删除");
                    mActivity.finish();
                } else {
                    forceUpdate();
                }
                break;
            case PuTaoConstants.EVENTBUS_ADD_OR_REMOVE_COLLECTION:
                forceUpdate();
                break;
        }
    }

    private void forceUpdate() {
        nextPage = 1;
        mIsLastPage = false;
        mDatalist.clear();
        doGetData();
    }

    private void saveStory() {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("album_id", album_id);
        params.put("story", mTinyAlbumItem.getStory());
        HttpRequestUtil.doHttpPostRequest(mContext, PuTaoConstants.API_POST_ALBUM_STORY,
                new RequestParams(HttpRequestUtil.buildHttpRequestParams(params)),
                new HttpRequestUtil.RequestResponseListener() {
                    @Override
                    public void success(int statuscode, String response) {
                        try {
                            JSONObject json = new JSONObject(response);
                            String msg = json.getString("msg");
                            showToast(msg);
                            EventBus.getDefault().post(new BasePostEvent(PuTaoConstants.EVENTBUS_REFRESH_ALBUM));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void failed(int statuscode, String response) {
                        Loger.d("response:::" + response);
                    }
                });
    }

    private boolean isDeleteMode() {
        return deleteMode;
    }

    private void setDeleteMode(boolean deleteMode) {
        this.deleteMode = deleteMode;

        if (isDeleteMode()) {
            back_btn.setBackgroundResource(R.drawable.all_button_close);

            btn_delete.setVisibility(View.VISIBLE);
            operate_btn.setVisibility(View.INVISIBLE);
        } else {
            back_btn.setBackgroundResource(R.drawable.all_button_back);

            for (int i = 0; i < mDatalist.size(); i++) {
                mDatalist.get(i).setChoose(false);
            }

            mTinyAblumAdapter.notifyDataSetChanged();

            btn_delete.setVisibility(View.INVISIBLE);
            operate_btn.setVisibility(View.VISIBLE);
        }

        updateStoryView();
    }

    /**
     * 获取当前相册的资料
     */
    void doGetData() {
        if (mIsLastPage || mIsRefreshing) {
            gv_album.onRefreshComplete();
            return;
        }
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("page", "" + nextPage);

        params.put("album_id", album_id);
        HttpRequestUtil.doHttpGetRequest(mContext, PuTaoConstants.API_GET_TINY_PHOTOLIST,
                new RequestParams(HttpRequestUtil.buildHttpRequestParams(params)),
                new HttpRequestUtil.RequestResponseListener() {
                    @Override
                    public void success(int statuscode, String response) {
                        if (!StringHelper.isEmpty(response)) {

                            if (HttpRequestUtil.getResponseCode(response).equals(HttpRequestUtil.ResponseCode.api_code_200)) {

                                try {
                                    JSONObject json = new JSONObject(response);
                                    String data = json.getString("data");
                                    doAnalyzeDataList(data);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                showToast(HttpRequestUtil.getResponseErrorMsg(response));
                            }
                        }
                    }

                    @Override
                    public void failed(int statuscode, String response) {
                        Loger.d("response:::" + response);
                    }
                });
        mIsRefreshing = true;
    }

    /**
     * 解析返回的标签相册列表数据
     *
     * @param data
     */
    void doAnalyzeDataList(String data) {
        try {
            mTinyAlbumItem = new Gson().fromJson(data, TinyAlbumItem.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (mTinyAlbumItem == null) {
            return;
        }

        updateUITopAndBottom();
        if (nextPage == 1) {
            mDatalist.clear();
        }

        mDatalist.addAll(mTinyAlbumItem.getList());
        mTinyAblumAdapter.notifyDataSetChanged();

        if (mDatalist.size() > 0) {
            gv_album.setVisibility(View.VISIBLE);
            no_photos.setVisibility(View.INVISIBLE);
        } else {
            no_photos.setVisibility(View.VISIBLE);
            gv_album.setVisibility(View.INVISIBLE);
        }

        nextPage = mTinyAlbumItem.getNext_page();
        gv_album.onRefreshComplete();
        mIsRefreshing = false;
        if (nextPage == -1 || nextPage == 0) {
            mIsLastPage = true;
        }
    }

    /**
     * 更新故事视图
     */
    private void updateStoryView() {

        String storyString = mTinyAlbumItem.getStory();

        story_tv.setText(storyString);

        if (story_tv.getText().length() > getResources().getInteger(R.integer.activity_tiny_album_story_fold_trim_length)) {
            if (isDeleteMode()) {
                story_tv_operate.setVisibility(View.INVISIBLE);
            } else {
                story_tv_operate.setVisibility(View.VISIBLE);
            }
        } else {
            story_tv_operate.setVisibility(View.INVISIBLE);
        }

        if (isDeleteMode()) {
            story_view.setVisibility(View.INVISIBLE);
        } else {
            story_view.setVisibility(View.VISIBLE);
        }


        //Loger.d("chen+++++updateStoryView(),storyString:" + storyString + ",story_tv.getTrimLength()=" + story_tv.getTrimLength() + ",story_tv.getText().length() =" + story_tv.getText().length());
    }

    /**
     * 更新Kiss视图
     */
    private void uodateKissView() {
        String praiseNums = mTinyAlbumItem.getPraiseNums();
        int kissnNum = StringHelper.stringToInt(praiseNums);
        if (kissnNum > 0) {
            tips_kiss.setSelected(true);
            kiss_num.setText("亲 " + praiseNums);
        } else {
            tips_kiss.setSelected(false);
            kiss_num.setText("亲一下");
        }
    }

    /**
     * 更新界面上的数据
     */
    private void updateUITopAndBottom() {

        title_tv.setText(mTinyAlbumItem.getTimeName() + "·" + mTinyAlbumItem.getTime());

        updateStoryView();

        uodateKissView();

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_btn:
                if (isDeleteMode()) {
                    setDeleteMode(false);
                } else {
                    finish();
                }
                break;
            case R.id.share_layout:

                if (mPopupWindow != null && mPopupWindow.isShowing()) {
                    mPopupWindow.dismiss();
                    mPopupWindow = null;
                } else {

                    queryShare(v);
                }

                break;
            case R.id.kiss_layout:
                kiss_album();
                break;
            case R.id.btn_delete:
                showDeletePhotoDialog();
                break;
            case R.id.no_photos:
                ActivityHelper.startActivity(mActivity, ActivityAlbumPhotoSelect.class);
                break;
            case R.id.story_view:
                showStoryEditDialog();
                break;
            case R.id.go_delete:
                if (!isCreateUser()&&!isAdmin()) {
                    showToast("不是您上传,您也不是管理员,不能删除!");
                    return;
                }

                if (isDeleteMode()) {
                    setDeleteMode(false);
                } else {
                    setDeleteMode(true);
                }
                break;
            case R.id.story_tv_operate:

                if (story_tv.isFold()) {
                    story_tv.setFold(false);
                    story_tv_operate.setText(getString(R.string.fold));
                } else {
                    story_tv_operate.setText(getString(R.string.unfold));
                    story_tv.setFold(true);
                }

                //Loger.d("chen+++++onClick()" + ",story_tv.getTrimLength()=" + story_tv.getTrimLength());
                break;
            default:
                break;
        }
    }

    private boolean isCreateUser() {
        boolean isCreateUser = mTinyAlbumItem.getUid().equals(CommonUtils.getUsrId());
        return isCreateUser;
    }

    private boolean isAdmin() {
        boolean isAdmin = mTinyAlbumItem.getIs_admin() == 1;
        return isAdmin;
    }

    public void queryShare(final View v) {
        MobclickAgent.onEvent(mContext, UmengTouchEvent.SHARE_ALBUM);
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("baby_id", CommonUtils.getBabyId());
        params.put("album_id", album_id);
        HttpRequestUtil.doHttpGetRequest(mActivity, PuTaoConstants.API_GET_SHARE_CONTENT,
                new RequestParams(HttpRequestUtil.buildHttpRequestParams(params)), new HttpRequestUtil.RequestResponseListener() {
                    @Override
                    public void success(int statuscode, String response) {
                        try {
                            //{"data":{"title":"未出生","name":"好好好"},"status":"200"}
                            JSONObject json = new JSONObject(response);
                            JSONObject data = json.getJSONObject("data");
                            String title = data.getString("title");
                            String webUrl = PuTaoConstants.Photo_API_Domain + "/album/album/albumView?album_id=" + album_id;
                            String photoUrl = mDatalist.get(0).getPhoto();
                            mPopupWindow = PtThirdSharePopupWindow.Create(mActivity, webUrl, photoUrl, title, PtThirdSharePopupWindow.SHARE_WEB);
                            mPopupWindow.showAtLocation(v, Gravity.BOTTOM, 0, 0);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void failed(int statuscode, String response) {
                        Loger.d("response:::" + response);
//                        hideLoading();
                    }
                });
    }


    void showStoryEditDialog() {
        MobclickAgent.onEvent(mContext, UmengTouchEvent.ADD_DESCRIPTION);

        if (!isCreateUser()&&!isAdmin()) {
            showToast("不是您上传,您也不是管理员,不能写故事");
            return;
        }

        new WriteStoryDialog(mContext)
                .setInputLimit(100)
                .setInputText(story_tv.getOriginalText().toString())
                .setDialogButtonOnClickListener(new WriteStoryDialog.DialogButtonOnClickListener() {
                    @Override
                    public void positiveOnClick(Dialog dialog, String importText) {
                        dialog.dismiss();
                        mTinyAlbumItem.setStory(importText);
                        updateStoryView();
                        saveStory();
                    }

                    @Override
                    public void negativeOnClick(Dialog dialog, String importText) {
                        dialog.dismiss();
                    }
                })
                .setMessage(getString(R.string.tiny_album_write_story_hint))
                .Create()
                .show();

    }


    /**
     * 删除照片的弹窗提示
     */
    private void showDeletePhotoDialog() {
        if (getChoosedPhotos().size() < 1) {
            showToast("请选择照片");
            return;
        }

        new ConfirmDialogBuilder(mContext)
                .setMessage("真的需要删除照片吗？")
                .setPositiveButton(getString(R.string.btn_cancle), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                    }
                })
                .setNegativeButton(getString(R.string.btn_ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        deleteChoosePhoto();
                    }
                })
                .Create()
                .show();

    }

    /**
     * 活取已选中的图片的Id
     *
     * @return
     */
    private ArrayList<String> getChoosedPhotos() {
        ArrayList<String> photo_ids = new ArrayList<String>();
        for (int i = 0; i < mDatalist.size(); i++) {
            if (mDatalist.get(i).isChoose()) {
                photo_ids.add(mDatalist.get(i).getPhoto_id());
            }
        }
        return photo_ids;
    }

    /**
     * 删除选中的照片
     */
    private void deleteChoosePhoto() {
        ArrayList<String> photo_ids = getChoosedPhotos();

        HashMap<String, String> params = new HashMap<String, String>();
        params.put("photo_ids", photo_ids.toString());
        params.put("baby_id", CommonUtils.getBabyId());

        HttpRequestUtil.doHttpPostRequest(mContext, PuTaoConstants.API_POST_PHOTOS_DELETE,
                new RequestParams(HttpRequestUtil.buildHttpRequestParams(params)), true,
                new HttpRequestUtil.RequestResponseListener() {
                    @Override
                    public void success(int statuscode, String response) {

                        try {
                            JSONObject json = new JSONObject(response);
                            String status = json.getString("status");
                            String msg = json.getString("msg");
                            if (status.equals(HttpRequestUtil.ResponseCode.api_code_200)) {
                                for (int i = mDatalist.size() - 1; i >= 0; i--) {
                                    if (mDatalist.get(i).isChoose()) {

                                        Map<String, String> map = new HashMap<String, String>();
                                        map.put("babyId", CommonUtils.getBabyId());
                                        map.put("photoId", mDatalist.get(i).getPhoto_id());
                                        ArrayList<FileInfo> fileInfos = (ArrayList<FileInfo>) FileUploadDBHelper.getInstance().queryList(map);
                                        if (fileInfos != null && fileInfos.size() > 0) {
                                            for (int j = 0; j < fileInfos.size(); j++) {
                                                FileInfo item = fileInfos.get(j);
                                                FileUploadDBHelper.getInstance().delete(item);
                                            }
                                        }
                                        mDatalist.remove(i);
                                    }
                                }
                                updateDeleteBtnText();
                                if (mDatalist.size() > 0) {
                                    no_photos.setVisibility(View.INVISIBLE);
                                } else {
                                    no_photos.setVisibility(View.VISIBLE);
                                }

                                mTinyAblumAdapter.notifyDataSetChanged();
                                EventBus.getDefault().post(new BasePostEvent(PuTaoConstants.EVENTBUS_REFRESH_ALBUM));
                            }
                            showToast(msg);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void failed(int statuscode, String response) {
                    }
                });


    }

    /**
     * 亲的动画~~
     */
    private void startKissAnimation() {
        Animation scaleAnimation = new ScaleAnimation(1.0f, 0.2f, 1.0f, 0.2f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(100);
        scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Animation scaleAnimation = new ScaleAnimation(0.2f, 1.2f, 0.2f, 1.2f,
                        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                scaleAnimation.setDuration(100);
                tips_kiss.startAnimation(scaleAnimation);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        tips_kiss.startAnimation(scaleAnimation);
    }

    /**
     * 亲相册~
     */
    private void kiss_album() {
        MobclickAgent.onEvent(mContext, UmengTouchEvent.KISS_ALBUM);
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("page", "" + nextPage);
        params.put("album_id", album_id);
        HttpRequestUtil.doHttpPostRequest(mContext, PuTaoConstants.API_POST_ALBUM_KISS,
                new RequestParams(HttpRequestUtil.buildHttpRequestParams(params)),
                new HttpRequestUtil.RequestResponseListener() {
                    @Override
                    public void success(int statuscode, String response) {
                        try {
                            JSONObject json = new JSONObject(response);
                            String msg = json.getString("msg");
                            if (HttpRequestUtil.getResponseCode(response).equals(HttpRequestUtil.ResponseCode.api_code_200)) {
                                //{"msg":"操作成功","data":{"praiseNums":"1"},"status":200}

                                String data = json.getString("data");
                                json = new JSONObject(data);
                                String praiseNums = json.getString("praiseNums");

                                mTinyAlbumItem.setPraiseNums(praiseNums);

                                uodateKissView();
                                EventBus.getDefault().post(new BasePostEvent(PuTaoConstants.EVENTBUS_REFRESH_ALBUM));
                            }
                            startKissAnimation();
                            showToast(msg);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void failed(int statuscode, String response) {
                        Loger.d("response:::" + response);
                    }
                });

    }
}
